#include "SkeletonAnimation.h"
#include "BoneOrientationNode.h"
SkeletonAnimation::SkeletonAnimation()
{
	heads = NULL;
	currentPose = NULL;
}
SkeletonAnimation::SkeletonAnimation(BoneOrientationNodeList * heads)
{
	this->heads = heads;
	currentPose = heads->GetTail();
}

SkeletonAnimation::SkeletonAnimation(BoneOrientationNode * skeletonPose)
{
	heads = new BoneOrientationNodeList(skeletonPose);
	currentPose = heads->GetTail();
}
SkeletonAnimation::~SkeletonAnimation()
{
	if(heads)
	{
		delete(heads);
		heads = NULL;
	}
}
void SkeletonAnimation::Add(BoneOrientationNode * skeletonPose)
{
	if(!heads)
	{
		heads = new BoneOrientationNodeList(skeletonPose);
		currentPose = heads->GetTail();
	}
	else
	{
		heads->Add(skeletonPose);
	}
}

void SkeletonAnimation::SetAnimation(Bone * boneHead)
{
	if(currentPose && boneHead)
	{
		BoneOrientationNode * head = currentPose->payload;
		
		if(head)
			boneHead->SetDesiredOrientation(head);
	}
}
void SkeletonAnimation::SetNextPose(Bone * head)
{
	if(currentPose)
	{
		currentPose = currentPose->prev;		
	}
	
	if(!currentPose)
		currentPose = heads->GetTail();
	
	SetAnimation(head);
}
void SkeletonAnimation::Reset()
{
	currentPose = heads->GetTail();
}
	